/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.elcom.emocbc.cbcgateway.httpclient;

import com.elcom.emocbc.cbcgateway.httpclient.xml.AckParser;
import com.elcom.emocbc.cbcgateway.httpclient.xml.BroadcastAck;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author GiangLT
 */
public class AckResponseHandler implements ResponseHandler<BroadcastAck> {

    private static final Logger logger = LoggerFactory.getLogger(AckResponseHandler.class);

    @Override
    public BroadcastAck handleResponse(HttpResponse hr) throws ClientProtocolException, IOException {
        String reponseContent = EntityUtils.toString(hr.getEntity());
        EntityUtils.consume(hr.getEntity());

        logger.info("<== HttpResponse received: {} {}", hr.toString(), reponseContent);
        AckParser ackParser = new AckParser();
        return ackParser.parseAck(reponseContent);
    }
}
